home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / public / bit / src / control.c < prev    next >
C/C++ Source or Header  |  1994-08-01  |  40KB  |  1,627 lines

  1. /*
  2.  * $Id: control.c,v 0.91 1994/02/20 00:53:19 zhao Pre-Release $
  3.  *
  4.  *. This file is part of BIT shareware package. After the two weeks of
  5.  *  free evaluation period, you are encouraged (required) to register
  6.  *  your copy for a small registration fee, which is $35 for personal use
  7.  *  and $50 for commercial, government and institutional use.
  8.  *
  9.  *  Copyright(c) 1993, 1994 by T.C. Zhao.
  10.  *  All rights reserved.
  11.  *
  12.  *  Permission to use, copy, and distribute this software in its entirety
  13.  *  for non-commercial purposes is hereby granted, provided that the
  14.  *  above shareware and copyright notices and this permission notice
  15.  *  appear in all copies and their documentation.
  16.  *
  17.  *  This software may be modified for your own use, but modified versions
  18.  *  may not be distributed without prior consent of the author.
  19.  *
  20.  *  This software is provided "as is" without expressed or implied
  21.  *  warranty of any kind.
  22.  *
  23.  *.
  24.  *
  25.  * Main forms. FilePanel and ControlPanel.
  26.  *
  27.  */
  28. #if !defined(lint) && defined(F_ID)
  29. char *id_cntl = "$Id: control.c,v 0.91 1994/02/20 00:53:19 zhao Pre-Release $";
  30. #endif
  31.  
  32. #include "bit.h"
  33. #include "extern.h"
  34.  
  35. static void create_forms(void);
  36. static void up_dn_cb(FL_OBJECT *, long);
  37. static FL_FORM *cntl, *info;
  38. static FL_OBJECT *etitle, *infog;
  39.  
  40. /**************************************************************
  41.  * Where the control window should be. Maybe called by init
  42.  *************************************************************/
  43. void
  44. set_control_window_position(int x, int y)
  45. {
  46.     create_forms();
  47.     cntl->x = x;
  48.     cntl->y = y;
  49. }
  50.  
  51. /**************************************************************
  52.  * map and show control window
  53.  ***************************************************************/
  54. long
  55. show_control_window(int x, int y, int w, int h, int bd)
  56. {
  57.     int place;
  58.  
  59.     create_forms();
  60.     if (cntl->visible)
  61.     return cntl->window;
  62.  
  63.     place = FL_PLACE_POSITION;
  64.  
  65.     if (w > 0 && h > 0)
  66.       {
  67.       prefposition(x, x + w - 1, y, y + h - 1);
  68.       place = FL_PLACE_FREE;
  69.       }
  70.     else if (x >= 0 || y >= 0)
  71.       {
  72.       fl_set_form_position(cntl, x, y);
  73.       }
  74.  
  75.     bit_show_form(cntl, place, bd, "BITControl");
  76.     set_cursor(cntl->window, CUR_HAND);
  77.     set_default_cursor(cntl->window, CUR_HAND);
  78.     return cntl->window;
  79. }
  80.  
  81. /******************************************************
  82.  * unmap control wndows
  83.  ******************************************************/
  84. void
  85. hide_control_window(void)
  86. {
  87.     create_forms();
  88.     if (cntl->visible)
  89.     bit_hide_form(cntl);
  90. }
  91.  
  92. /********************************************************/
  93. long
  94. get_control_wid(void)
  95. {
  96.     create_forms();
  97.     return cntl->window;
  98. }
  99.  
  100. /*** Save current control window position to file *****/
  101. void
  102. write_control_window_position(FILE * fp)
  103. {
  104.     fprintf(fp, "%d %d # Lower-left corener of ControlPanel\n",
  105.         (int) cntl->x, (int) cntl->y);
  106. }
  107.  
  108.  
  109. /*********************************************************
  110.  * Editing groups
  111.  * Editing is defined as any transformation that changes one
  112.  * or more field in the image structure.
  113.  *******************************************************{**/
  114.  
  115. #define MAXSHOWN 15
  116. static FL_OBJECT *bedit[MAXSHOWN + 1];
  117. static FL_OBJECT *edgrp, *pgrp, *cgrp, *mgrp, *exgrp;
  118. static int maxshown;
  119.  
  120. /************************************************************
  121.  * Ordinarily all editing function blocks double entry and that
  122.  * is done via deactivation of groups/forms. In some cases, we
  123.  * might want to have a particular group active
  124.  *************************************************************/
  125. enum exclusions_
  126.   {
  127.       EX_NONE = 0, EX_PAN = 1, EX_EDIT = 2,
  128.       EX_MISC = 1 << 2, EX_CONV = 1 << 3, EX_EXB = 1 << 4
  129.   };
  130.  
  131. /****** All editing functions takes the following form **** */
  132. typedef int (*Igfptr) (IPTR);
  133.  
  134. typedef struct
  135.   {
  136.       const char *name;        /* editing function name     */
  137.       Igfptr edit;        /* the function itself       */
  138.       int bcolor;        /* button color when pressed */
  139.       int disp;            /* if demands a display      */
  140.       int exclude;        /* deactivate edit panel     */
  141.   }
  142. Edit_t;
  143.  
  144. extern int do_ibrowse(IPTR);
  145.  
  146. /*
  147.  * main structure. If more editing functions than that can be shown, a
  148.  * flip button will appear.
  149.  */
  150.  
  151. static Edit_t edit[] =
  152. {
  153.     {"Crop", do_crop, FL_YELLOW, 0, EX_PAN},
  154.     {"Cut&Paste", do_cut_paste, FL_YELLOW, 1, EX_PAN},
  155.     {"Text", do_text, FL_GREEN, 0, EX_PAN},
  156.     {"Marking", img_marking, FL_GREEN, 1, EX_PAN},
  157.     {"Rotate", do_rotate, FL_YELLOW, 1, EX_NONE},
  158.     {"Scale", do_scale, FL_YELLOW, 1, EX_NONE},
  159.     {"PixTran", do_coledit, FL_GREEN, 0, EX_PAN},
  160.     {"PixelEdit", pixel_edit, FL_YELLOW, 0, EX_NONE},
  161.     {"Merge", do_merge, FL_YELLOW, 0, EX_NONE},
  162.     {"Paint", img_paint, FL_YELLOW, 1, EX_PAN},
  163.     {"EditMap", do_editmap, FL_YELLOW, 0, EX_NONE},
  164.     {"Smooth", img_smooth, FL_RED, 0, EX_PAN},
  165.     {"Sharpen", do_sharpen, FL_RED, 1, EX_NONE},
  166.     {"MedianF", do_medianf, FL_YELLOW, 0, EX_NONE},
  167.     {"ImgDiff", img_diff, FL_RED, 1, EX_NONE},
  168.     {"Edge", img_edge, FL_RED, 1, EX_NONE},
  169.     {"Enhance", img_enhance, FL_RED, 1, EX_NONE},
  170.     {"Measure", img_measure, FL_GREEN, 0, EX_NONE},
  171.     {"Histogram", img_show_histogram, FL_YELLOW, 0, EX_NONE},
  172.     {"Normalize", img_norm, FL_RED, 1, EX_NONE},
  173. #if 0
  174.     {"FFT", img_fft, FL_YELLOW, 0, EX_NONE}
  175.     {"SimpleCP", do_scp, FL_YELLOW, 0, 1},
  176.     {"HistoSpec", do_hspec, FL_YELLOW, 0, 1},
  177. #endif
  178. };
  179.  
  180. static int totaledit = sizeof(edit) / sizeof(edit[0]);
  181. static int offset;
  182.  
  183. /**************************************************************
  184.  * Selectively leave some editing group active
  185.  *************************************************************/
  186. static void
  187. exclude_groups(int exclude, void (*what) (FL_OBJECT *))
  188. {
  189.     if (!(exclude & EX_EDIT))
  190.     what(edgrp);
  191.  
  192.     if (!(exclude & EX_EXB))
  193.     what(exgrp);
  194.  
  195.     if (!(exclude & EX_PAN))
  196.     what(pgrp);
  197.  
  198.     if (!(exclude & EX_MISC))
  199.     what(mgrp);
  200.  
  201.     if (!(exclude & EX_CONV))
  202.     what(cgrp);
  203. }
  204.  
  205. /***************************************************************
  206.  * When an edit button is pressed, this routine is activated
  207.  **************************************************************/
  208.  
  209. /* ARGSUSED */
  210. static void
  211. edit_cb(FL_OBJECT * obj, long i)
  212. {
  213.     static int inedit;
  214.     Edit_t *cedit = edit + i;    /* curent editing structure  */
  215.     int is_ci;
  216.  
  217.     /*
  218.      * All editing functions are non re-entrant by nature, must not allow
  219.      * double entry. Further, must have a valid image to edit and make
  220.      * special provision for paint where we can create images on the fly
  221.      */
  222.  
  223.     if (inedit ||
  224.     (cedit->edit != img_paint && !image_ready(imgptr, cedit->name)))
  225.     return;
  226.  
  227.     inedit = 1;
  228.  
  229.     /* block double entry with provision for exclusions */
  230.  
  231.     exclude_groups(cedit->exclude, fl_deactivate_object);
  232.  
  233.     /* remember current image type */
  234.     is_ci = IS_CI(imgptr);
  235.  
  236.     if (cedit->edit(imgptr) >= 0)
  237.       {
  238.       /* if image type change, do it for text and sgf as well */
  239.       if (!is_ci && IS_CI(imgptr))
  240.         {
  241.         text_to_cmap();
  242.         sgf_to_cmap();
  243.         }
  244.  
  245.       /* if requires re-display, do it here */
  246.       if (cedit->disp)
  247.           imgptr->io->display(imgptr, double_buf ? -1 : 4, 1);
  248.  
  249.       update_image_info(imgptr);
  250.       }
  251.  
  252.     exclude_groups(cedit->exclude, fl_activate_object);
  253.  
  254.     inedit = 0;
  255. }
  256.  
  257. /***** walks up and down the editing functions ******/
  258. /* ARGSUSED */
  259. static void
  260. up_dn_cb(FL_OBJECT * obj, long dir)
  261. {
  262.     int i;
  263.  
  264.     fl_freeze_form(cntl);
  265.  
  266.     if ((offset + maxshown) <= totaledit)
  267.     offset += maxshown;
  268.     else if (offset >= maxshown)
  269.     offset -= maxshown;
  270.  
  271.     for (i = 0; i < maxshown && i + offset < totaledit; i++)
  272.       {
  273.       fl_set_object_label(bedit[i], edit[i + offset].name);
  274.       fl_show_object(bedit[i]);
  275.       fl_set_call_back(bedit[i], edit_cb, i + offset);
  276.       }
  277.  
  278.     for (; i < maxshown; i++)
  279.     fl_hide_object_only(bedit[i]);
  280.     fl_unfreeze_form(cntl);
  281. }
  282.  
  283.  
  284. /* End of Ending group } */
  285.  
  286.  
  287. /****************************************************************
  288.  *  Type conversion group
  289.  *************************************************************{**/
  290. typedef struct
  291. {
  292.     const char *lab;        /* type name for the image */
  293.     IMG_TYPE type;        /* internal name           */
  294. }
  295. C_t;
  296.  
  297. /* maybe stick a quant some where */
  298. static C_t ct[] =
  299. {
  300.     {"Color(RGB)", T_RGBA},
  301.     {"Color(Map)", T_CMAP},
  302.     {"Gray(Map)", T_GMAP},
  303.     {"Gray(RGB)", T_GRAY},
  304.     {"B&W", T_BW}
  305. };
  306.  
  307. static int totalct = sizeof(ct) / sizeof(ct[0]);
  308.  
  309. /* ARGSUSED */
  310. static void
  311. type_cb(FL_OBJECT * obj, long j)
  312. {
  313.     C_t *cct = ct + j;        /* current conversion structure */
  314.  
  315.     show_busy("Converting ...");
  316.     if (img_convert_type(imgptr, cct->type) >= 0)
  317.       {
  318.       /* force the type to be the requested */
  319.       imgptr->type = cct->type;
  320.       if (cct->type == T_GRAY)
  321.         {
  322.         text_to_gray();
  323.         sgf_to_gray();
  324.         }
  325.       else if (IS_CI(imgptr))
  326.         {
  327.         text_to_cmap();
  328.         sgf_to_cmap();
  329.         }
  330.       update_image_info(imgptr);
  331.       imgptr->io->display(imgptr, 0, 0);
  332.       }
  333.     end_busy();
  334. }
  335.  
  336. /* End of type conversion group } */
  337.  
  338. /***************************************************************
  339.  * External pipes and filters
  340.  **********************************************************{****/
  341.  
  342. #define EXT_CONVOLV  1
  343. #define EXT_FILTER   2
  344.  
  345. /* ARGSUSED */
  346. static void
  347. ext_cb(FL_OBJECT * obj, long what)
  348. {
  349.     if (!image_ready(imgptr, "ExtBinding"))
  350.     return;
  351.  
  352.     ((what == EXT_CONVOLV) ? do_ext_convolv : do_ext_filter) (imgptr);
  353. }
  354.  
  355. /* End of external pipes  } */
  356.  
  357. /************************************************************
  358.  * Image panning
  359.  ********************************************************{**/
  360.  
  361. static FL_OBJECT *pspeed;
  362.  
  363. int
  364. get_pan_speed(void)
  365. {
  366.     return fl_get_counter_value(pspeed);
  367. }
  368.  
  369. /* ARGSUSED */
  370. static void
  371. pan_cb(FL_OBJECT * ob, long dir)
  372. {
  373.     image_pan(imgptr, dir, get_pan_speed());
  374. }
  375.  
  376. /******************* End of pan  **********************}**/
  377.  
  378. /************************************************************
  379.  * Misc control group
  380.  *********************************************************{**/
  381. typedef enum
  382. {
  383.     MISC_HIDE,
  384.     MISC_ZOOM,
  385.     MISC_INFO,
  386.     MISC_SYSMAP,
  387.     MISC_DELETE
  388. } menum_t;
  389.  
  390. struct tmp_
  391.   {
  392.       const char *lab;
  393.       const char *scut;
  394.       int bcol;
  395.       menum_t cbi;
  396.   };
  397.  
  398. static struct tmp_ misccn[] =
  399. {
  400.     {"Magnify", "Zz", FL_GREEN, MISC_ZOOM},
  401.     {"HideC", "Cc", FL_YELLOW, MISC_HIDE},
  402.     {"ToggleF", "Ff", FL_YELLOW, MISC_INFO},
  403.     {"SysMap", "Mm", FL_YELLOW, MISC_SYSMAP},
  404.     {"Delete", "Dd", FL_RED, MISC_DELETE}
  405. };
  406.  
  407. static int totalmisc = sizeof(misccn) / sizeof(struct tmp_);
  408.  
  409. /******* Remove a file from disk ************/
  410. static void
  411. delete_file(void)
  412. {
  413.     char *ptmp = 0;
  414.     int goahead;
  415.  
  416.  
  417.     goahead = (always_delete || yes_no("DelFromDiskConfirm",
  418.              ptmp = vstrcat("Remove ", imgptr->ifile, " from disk"),
  419.                        "Are You Sure ?", 0));
  420.  
  421.     if (goahead)
  422.       {
  423.       if (remove(imgptr->ifile))
  424.         {
  425.         M_warn("Delete", "Delete %s failed", imgptr->ifile);
  426.         }
  427.       else
  428.         {
  429.         /* no sense keeping it on the list */
  430.         delete_from_list1(imgptr->ifile);
  431.  
  432.         /* also remove its associated thumnails */
  433.         if (auto_remove_thumbnail)
  434.             del_thumbnail(0, imgptr->ifile);
  435.         }
  436.  
  437.       if (ptmp)
  438.           free_vstrcat(ptmp);
  439.       }
  440. }
  441.  
  442. /*********** Misc function handler *********************/
  443. #include "dmalloc.h"        /* for free */
  444. /* ARGSUSED */
  445. static void
  446. misc_cb(FL_OBJECT * ob, long j)
  447. {
  448.     switch (j)
  449.       {
  450.       case MISC_HIDE:        /* hide control form   */
  451.       bit_hide_form(cntl);
  452.       break;
  453.  
  454.       case MISC_ZOOM:        /* actvete zooming      */
  455.       image_zoom(imgptr);
  456.       break;
  457.  
  458.       case MISC_INFO:        /* toggle info panel    */
  459.       if (info->visible)
  460.           hide_info_window();
  461.       else
  462.           show_info_window(-1, -1, -1, -1, 1);
  463.       break;
  464.  
  465.       case MISC_SYSMAP:    /* restore system colormap */
  466.       set_sysmap(0);
  467.       break;
  468.  
  469.       case MISC_DELETE:
  470.       if (imgptr && imgptr->ifile[0])
  471.           delete_file();
  472.       break;
  473.       }
  474. }
  475. /*********** End of misc control } ***********/
  476.  
  477.  
  478. /*******************************************************************
  479.  *   show more info about current state of the program
  480.  *******************************************************************/
  481.  
  482. /**** add one more line ****/
  483. void
  484. showit(const char *s)
  485. {
  486.     char more[150];
  487.     (void) strncat(strcpy(more, "@f"), s, sizeof(more) - 1);
  488.     add_to_help(more);
  489. }
  490.  
  491. #define YN(a)  (a) ? "Yes":"No"
  492.  
  493. /* ARGSUSED */
  494. static void
  495. show_image_info(FL_OBJECT * obj, long nouse)
  496. {
  497.     char line[120];
  498.     char gcdir[300];
  499.     int i, k;
  500.     const char *fmt2 = "%11s %s";
  501.  
  502.     set_help_title("CurrentInfo");
  503.     showit(" ");
  504.     sprintf(line, "@b@c ImageInfo");
  505.     showit(line);
  506.  
  507.     if (!imgptr || !imgptr->io)
  508.       {
  509.       showit("No image");
  510.       goto otherinfo;
  511.       }
  512.  
  513.     sprintf(line, fmt2, "Filename", imgptr->ifile);
  514.     showit(line);
  515.     sprintf(line, fmt2, "Format", imgptr->io->info);
  516.     showit(line);
  517.     sprintf(line, "%11s: %s(%s)", "Type", IS_CI(imgptr) ? "Cmap" : "RGB",
  518.         IS_GRAY(imgptr) ? "Gray" : "Color");
  519.     showit(line);
  520.     sprintf(line, "%11s: %d X %d", "Size", imgptr->w, imgptr->h);
  521.     showit(line);
  522.  
  523.     if (imgptr->ok)
  524.       {
  525.       sprintf(line, "%11s: (%d,%d)", "Location", imgptr->xi, imgptr->yi);
  526.       showit(line);
  527.       }
  528.  
  529.     sprintf(line, "%11s: %d bytes", "PixelSize", imgptr->esize);
  530.     showit(line);
  531.     sprintf(line, "%11s: %lu bytes", "RasterSize", imgptr->size);
  532.     showit(line);
  533.     if (imgptr->cmap && imgptr->cmap->colors)
  534.       {
  535.       sprintf(line, fmt2, "Colormap", "Yes");
  536.       showit(line);
  537.       sprintf(line, "%11s: %d", "Colors", imgptr->cmap->colors);
  538.       showit(line);
  539.       sprintf(line, fmt2, "Packed", YN(imgptr->cmap->packed));
  540.       showit(line);
  541.       }
  542.     else
  543.       {
  544.       sprintf(line, fmt2, "Colormap", "No");
  545.       showit(line);
  546.       }
  547.     sprintf(line, fmt2, "Status", imgptr->ok ? "Ready" : "Not Ready");
  548.     showit(line);
  549.  
  550. /*
  551.  * All paths
  552.  */
  553.   otherinfo:
  554.     showit("@b@c FileInfo");
  555.     getcwd(gcdir, 288);
  556.     sprintf(line, fmt2, "CurrentDir:", gcdir);
  557.     showit(line);
  558.     sprintf(line, fmt2, "BitDir:", bitpath);
  559.     showit(line);
  560.     sprintf(line, fmt2, "HelpDir:", helppath);
  561.     showit(line);
  562.     showit(" ");
  563.  
  564. /*
  565.  * misc info about program
  566.  */
  567.     showit("@b@c MiscInfo");
  568.     sprintf(line, "%11s: %d X %d", "ScreenSize",
  569.         (int) getgdesc(GD_XPMAX), (int) getgdesc(GD_YPMAX));
  570.     showit(line);
  571.  
  572.     sprintf(line, "%11s: %d\t%12s: %d", "ScreenDPI", get_scr_dpi(),
  573.         "DefaultMaps", get_number_of_defmaps());
  574.     showit(line);
  575.     sprintf(line, "%11s: %dK\t%12s: %dK ", "FontCache",
  576.         get_fm_cache(), "Used", get_fm_cacheused());
  577.     showit(line);
  578.     sprintf(line, "%11s: %ld", "MainWid", win_id);
  579.     showit(line);
  580.     sprintf(line, "%15s: %ldX%ld", "Size", win_w, win_h);
  581.     showit(line);
  582.     sprintf(line, "%15s: (%ld,%ld)", "Origin", win_xo, win_yo);
  583.     showit(line);
  584.     sprintf(line, "%11s: %ld\t%11s:%ld", "InfoWid", get_info_wid(),
  585.         "ControlWid", get_control_wid());
  586.     showit(line);
  587.     sprintf(line, "%11s: %ld", "CurrentWid", winget());
  588.     showit(line);
  589.     sprintf(line, "%11s: %d", "WMhandler", total_wm_handler());
  590.     showit(line);
  591.     sprintf(line, "%11s: %d", "GLQhandler", total_GLQ_handler());
  592.     showit(line);
  593.     sprintf(line, "%11s: %s", "FormDblbuf", YN(fl_doublebuf));
  594.     showit(line);
  595. /*
  596.  *  C & P info
  597.  */
  598.     showit(" ");
  599.     showit("@b@c CutPasteInfo");
  600.     if ((k = no_of_cut_paste_buffers()) > 0)
  601.       {
  602.       for (i = 0; i < k; i++)
  603.         {
  604.         sprintf(line, "%s", cut_paste_buffer_name(i));
  605.         showit(line);
  606.         }
  607.       }
  608.     else
  609.     showit("@c None");
  610. /*
  611.  * Text info
  612.  */
  613.     showit(" ");
  614.     showit("@b@c Text Info");
  615.     if ((k = number_of_text()) > 0)
  616.       {
  617.       int r, g, b;
  618.       sprintf(line, "@c Total %d strings", k);
  619.       showit(line);
  620.       for (i = 0; i < k; i++)
  621.         {
  622.         sprintf(line, "@s%d: %s ", i + 1, get_text_string(i));
  623.         showit(line);
  624.         get_text_color(i, &r, &g, &b);
  625.         sprintf(line, "   Fontname: %s, size=%.1f",
  626.             get_text_fontname(i), get_text_fontsize(i));
  627.         showit(line);
  628.         sprintf(line, "   Color: r=%d g=%d b=%d", r, g, b);
  629.         showit(line);
  630.         get_text_location(i, &r, &g);
  631.         sprintf(line, "   Location: (%d %d) %s", r, g,
  632.             (get_text_rotation(i) > 0.1) ? "Rotated" : "");
  633.         showit(line);
  634.         }
  635.       }
  636.     else
  637.     showit("@c None");
  638. /*
  639.  * Simple geometric figures info
  640.  */
  641.     showit(" ");
  642.     showit("@b@c Marking Info");
  643.     if ((k = number_of_sgf()) > 0)
  644.       {
  645.       int x, y, t, w, h, r, g, b, a;
  646.       sprintf(line, "@c Total %d sgfs", k);
  647.       showit(line);
  648.       for (i = 0; i < k; i++)
  649.         {
  650.         sprintf(line, "%d: %s", i + 1, sgf_name(i));
  651.         showit(line);
  652.         get_sgf_info(i, &x, &y, &w, &h, &t, &b, &a);
  653.         sprintf(line,
  654.             "   Where: (%d,%d)  Size: (%d,%d) Lwidth:%d Rot:%d",
  655.             x, y, w, h, t, a);
  656.         showit(line);
  657.         get_sgf_color(i, &r, &g, &b);
  658.         sprintf(line, "   Color: R=%d G=%d B=%d", r, g, b);
  659.         showit(line);
  660.         }
  661.       }
  662.     else
  663.     showit("@c None");
  664.     show_help(0, 0, -1, -1, 0);
  665. }
  666.  
  667. /* ARGSUSED */
  668. static void
  669. special_cb(FL_OBJECT * ob, long q)
  670. {
  671.     if (imgptr->ok <= 0)
  672.     return;
  673.     if (imgptr->io && imgptr->io->special)
  674.     imgptr->io->special(imgptr);
  675.     else
  676.     show_image_info(ob, q);
  677. }
  678.  
  679. /* End of editing forms */
  680.  
  681. /************************************************************************
  682.  *
  683.  * Informational forms and also some control
  684.  *
  685.  ************************************************************************/
  686. static FL_OBJECT *freport[5], *pslider, *ptext;
  687. static FL_OBJECT *mreport[4], *mrptg;
  688.  
  689. /*
  690.  * Global functions to manipulate the info panel
  691.  */
  692. long
  693. get_info_wid(void)
  694. {
  695.     create_forms();
  696.     return info->window;
  697. }
  698.  
  699. void
  700. hide_info_window(void)
  701. {
  702.     if (info->visible)
  703.     bit_hide_form(info);
  704. }
  705.  
  706. /**************************************************************
  707.  * Where to place info window. May be called by init
  708.  *************************************************************/
  709. void
  710. set_info_window_position(int x, int y)
  711. {
  712.     create_forms();
  713.     info->x = x;
  714.     info->y = y;
  715. }
  716.  
  717. long
  718. show_info_window(int x, int y, int w, int h, int b)
  719. {
  720.     int i, place;
  721.  
  722.     create_forms();
  723.  
  724.     if (info->visible)
  725.     return info->window;
  726.  
  727.     place = FL_PLACE_POSITION;
  728.     if (w > 0 && h > 0)
  729.       {
  730.       prefposition(x, x + w - 1, y, y + h - 1);
  731.       place = FL_PLACE_FREE;
  732.       }
  733.     else if (x >= 0 || y >= 0)
  734.       {
  735.       fl_set_form_position(info, x, y);
  736.       }
  737.     /* need to hide all */
  738.     fl_hide_object(pslider);
  739.     fl_hide_object(ptext);
  740.  
  741.     for (i = 0; i < 4; i++)
  742.     fl_hide_object(mreport[i]);
  743.  
  744.     bit_show_form(info, place, b, "File");
  745.     return info->window;
  746. }
  747.  
  748. void
  749. write_info_window_position(FILE * fp)
  750. {
  751.     fprintf(fp, "%d %d # Lower-left corener of FilePanel\n",
  752.         (int) info->x, (int) info->y);
  753. }
  754.  
  755. /* make info window always active */
  756. void
  757. deactivate_all_forms(void)
  758. {
  759.     create_forms();
  760.     fl_deactivate_all_forms();
  761.     fl_activate_form(info);
  762. }
  763.  
  764.  
  765. void
  766. update_color_info(IPTR im)
  767. {
  768.     char lstr[70];
  769.     const char *p = "";
  770.  
  771.     if (IS_CI(im))
  772.       {
  773.       p = IS_BW(im) ? "B&W" : (IS_GRAY(im) ? "Graymap" : "Map");
  774.       if (im->cmap->ucolors && im->cmap->ucolors < im->cmap->colors)
  775.           sprintf(lstr, "%s:%d(%d uniq)", p, im->cmap->colors,
  776.               im->cmap->ucolors);
  777.       else
  778.           sprintf(lstr, "%s:%d", p, im->cmap->colors);
  779.       }
  780.     else if (IS_CPACK(im))
  781.       {
  782.       p = IS_GRAY(im) ? "Grayscale" : "RGB";
  783.       if (im->colors > 0)
  784.           sprintf(lstr, "%s:%d", p, im->colors);
  785.       else
  786.           strcpy(lstr, p);
  787.       }
  788.     else
  789.       {
  790.       Bark("UpdateInfo", "Should not happen");
  791.       clean_up();
  792.       }
  793.     fl_set_object_label(freport[3], lstr);
  794. }
  795.  
  796. /****** show current image info, faking jpeg ********/
  797. void
  798. update_size_info(int w, int h)
  799. {
  800.     char lstr[100];
  801.  
  802.     /* special for w==1 and h==1, meaning dimension not known yet */
  803.     if ((w == 1 && h == 1) || report_level < 0)
  804.     return;
  805.     sprintf(lstr, "%dX%d", w, h);
  806.     fl_set_object_label(freport[2], lstr);
  807. }
  808.  
  809. void
  810. update_filename(char *f)
  811. {
  812.     fl_set_object_label(freport[0], f ? f : "None");
  813. }
  814.  
  815. void
  816. update_format_info(IPTR im)
  817. {
  818.     fl_set_object_label(freport[1], im->info);
  819. }
  820.  
  821.  
  822. void
  823. update_misc_info(IPTR im)
  824. {
  825.     fl_set_object_label(freport[4], im->info);
  826. }
  827.  
  828. /***** special hack: if img->esize == img->w == img->h == 1, do nothing ***/
  829. void
  830. update_image_info(IPTR im)
  831. {
  832.     char brief[100];
  833.  
  834.     if (!im)
  835.       {
  836.       fl_freeze_form(info);
  837.       fl_set_object_label(freport[0], "None");
  838.       fl_set_object_label(freport[1], " ");
  839.       fl_set_object_label(freport[2], " ");
  840.       fl_set_object_label(freport[3], " ");
  841.       fl_set_object_label(freport[4], " ");
  842.       fl_unfreeze_form(info);
  843.       fl_set_object_label(etitle, "None");
  844.       return;
  845.       }
  846.  
  847.     if ((im->h == 1 && im->w == 1) || report_level < 0)
  848.     return;
  849.  
  850.     fl_freeze_form(info);
  851.  
  852.     if (strlen(im->ifile) > 22)
  853.       {
  854.       Strncpy(brief, im->ifile, 22);
  855.       fl_set_object_label(freport[0], brief);
  856.       }
  857.     else
  858.     fl_set_object_label(freport[0], im->ifile);
  859.  
  860.     fl_set_object_label(freport[1], im->info);
  861.     update_size_info(im->w, im->h);
  862.     update_color_info(im);
  863.     fl_set_object_label(freport[4], im->misc);
  864.     fl_unfreeze_form(info);
  865.  
  866.     /* generate a brief info for edit form */
  867.     sprintf(brief, "%s (%s %dX%d %s)", im->ifile, im->key,
  868.      im->w, im->h, IS_GRAY(im) ? "Gray" : (IS_BW(im) ? "BW" : "Color"));
  869.     fl_set_object_label(etitle, brief);
  870. }
  871.  
  872. /*********** Misc info *****************/
  873. void
  874. show_rect_size(int w, int h)
  875. {
  876.     char lstr[100];
  877.  
  878.     if (!info->visible)
  879.     return;
  880.     sprintf(lstr, "Size:\t%dX%d", w, h);
  881.     fl_set_object_label(mreport[0], lstr);
  882.     if (!mreport[0]->visible)
  883.     fl_show_object(mreport[0]);
  884. }
  885.  
  886. void
  887. hide_rect_size(void)
  888. {
  889.     if (!info->visible || !mreport[0]->visible)
  890.     return;
  891.     fl_hide_object_only(mreport[0]);
  892. }
  893.  
  894. void
  895. show_rect_ori(int x, int y)
  896. {
  897.     char lstr[100];
  898.  
  899.     if (!info->visible)
  900.     return;
  901.     sprintf(lstr, "Ori:\t(%d,%d)", x, y);
  902.     fl_set_object_label(mreport[1], lstr);
  903.     if (!mreport[1]->visible)
  904.     fl_show_object(mreport[1]);
  905. }
  906.  
  907. void
  908. show_rect_all(int x, int y, int w, int h, int dotheta)
  909. {
  910.     float theta;
  911.     char treport[10];
  912.  
  913.     if (!info->visible)
  914.     return;
  915.  
  916.     fl_freeze_form(info);
  917.     show_rect_ori(x, y);
  918.     show_rect_size(w, h);
  919.     if (dotheta)
  920.       {
  921.       get_theta(w, h, &theta);
  922.       sprintf(treport, "Theta=%.2f", theta);
  923.       show_misc_info(treport);
  924.       }
  925.     fl_unfreeze_form(info);
  926. }
  927.  
  928. /********* Hide alll misc. infomation ***************/
  929. void
  930. hide_rect_all(void)
  931. {
  932.     int i;
  933.  
  934.     if (!info->visible)
  935.     return;
  936.     fl_freeze_form(info);
  937.     for (i = 0; i < 4; i++)
  938.     fl_hide_object_only(mreport[i]);
  939.     fl_unfreeze_form(info);
  940. }
  941.  
  942. void
  943. show_misc_info2(const char *s)
  944. {
  945.     if (!info->visible)
  946.     return;
  947.     fl_set_object_label(mreport[2], s);
  948.     if (!mreport[2]->visible)
  949.     fl_show_object(mreport[2]);
  950. }
  951.  
  952. void
  953. hide_misc_info2(void)
  954. {
  955.     fl_hide_object_only(mreport[2]);
  956. }
  957.  
  958. void
  959. show_misc_info(const char *s)
  960. {
  961.     if (!info->visible)
  962.     return;
  963.     fl_set_object_label(mreport[3], s);
  964.     if (!mreport[3]->visible)
  965.     fl_show_object(mreport[3]);
  966. }
  967.  
  968. void
  969. show_rect_speed(int sp)
  970. {
  971.     char lstr[100];
  972.  
  973.     if (!info->visible)
  974.     return;
  975.     sprintf(lstr, "Speed:%d", sp);
  976.     show_misc_info2(lstr);
  977. }
  978.  
  979. /* whatever passed is always relative to window */
  980. void
  981. show_mouse_position(int x, int y)
  982. {
  983.     char loc[20];
  984.  
  985.     if (report_mouse == 0)
  986.     return;
  987.  
  988.     if (report_mouse == 1 || !imgptr)
  989.       {                /* relative to window */
  990.       sprintf(loc, "(%d %d)", x, y);
  991.       }
  992.     else
  993.       {
  994.       sprintf(loc, "(%d %d)", x - imgptr->xi, y - imgptr->yi);
  995.       }
  996.     show_misc_info2(loc);
  997. }
  998.  
  999. void
  1000. hide_mouse_position(void)
  1001. {
  1002.     hide_misc_info2();
  1003. }
  1004.  
  1005. void
  1006. hide_misc_info(void)
  1007. {
  1008.     fl_hide_object_only(mreport[3]);
  1009. }
  1010.  
  1011.  
  1012.  
  1013. /********************************************************************
  1014.  * File IO group
  1015.  *******************************************************************{*/
  1016. enum nouse
  1017. {
  1018.     F_CONFIG, F_LOAD, F_WRITE, F_QUIT
  1019. };
  1020.  
  1021. typedef struct
  1022.   {
  1023.       enum nouse cbi;        /* call back parameter */
  1024.       const char *lab;        /* button label        */
  1025.       const char *scut;        /* shortcuts            */
  1026.   }
  1027. Fio_t;
  1028.  
  1029. static Fio_t fiob[] =
  1030. {
  1031.     {F_CONFIG, "Setup", "sS"},
  1032.     {F_LOAD, "Load", "Ll"},
  1033.     {F_WRITE, "Write", "Ww"},
  1034.     {F_QUIT, "Quit", "^QQq"}
  1035. };
  1036.  
  1037. static int totalfio = sizeof(fiob) / sizeof(fiob[0]);
  1038. static FL_OBJECT *iogroup;
  1039.  
  1040. /*******************************************************************
  1041.  * Handle File IO requests.
  1042.  *
  1043.  * Since load/write/setup uses some command area, they should not
  1044.  * be active simultanousely. need fix individual routine before
  1045.  * remove the blocking here
  1046.  *******************************************************************/
  1047.  
  1048. /*ARGSUSED*/
  1049. static void
  1050. file_cb(FL_OBJECT * ob, long what)
  1051. {
  1052.     if (what == F_QUIT)
  1053.       {
  1054.       if (yes_no("QUIT", "Are you sure ?", "", 0))
  1055.           clean_up();
  1056.       return;
  1057.       }
  1058.  
  1059.     fl_deactivate_object(iogroup);
  1060.  
  1061.     switch (what)
  1062.       {
  1063.       case F_CONFIG:
  1064.       config_sys();
  1065.       break;
  1066.  
  1067.       case F_LOAD:
  1068.       load_files();
  1069.       break;
  1070.  
  1071.       case F_WRITE:
  1072.       do_dump(imgptr);
  1073.       break;
  1074.       }
  1075.  
  1076.     fl_activate_object(iogroup);
  1077. }
  1078.  
  1079. /***********************************************************************
  1080.  * Print a breif help messages in a browser with version info
  1081.  **********************************************************************/
  1082. /* ARGSUSED */
  1083. void
  1084. version_cb(FL_OBJECT * r, long what)
  1085. {
  1086.     const char **p = p_version;
  1087.     char lstr[100];
  1088.     int i = 1;
  1089.  
  1090.     load_help("main.hlp", "ProgramInfo");
  1091.     insert_help(" ", 1);
  1092.  
  1093.     do
  1094.       {
  1095.       sprintf(lstr, "@C1@c@b%s", rm_rcs_kw(*p));
  1096.       ++i;
  1097.       insert_help(lstr, i);
  1098.       }
  1099.     while (*++p);
  1100.  
  1101.     /* list all supported formats */
  1102.     enumerate_formats(showit);
  1103.     show_help(0, 0, -1, -1, 0);
  1104. }
  1105.  
  1106. /******************************************************************
  1107.  * END OF FILE IO GROUP
  1108.  *****************************************************************}*/
  1109.  
  1110.  
  1111. /* misc controls on info form */
  1112. typedef enum
  1113. {
  1114.     IMISC_BROWSE,
  1115.     IMISC_REPAINT,
  1116.     IMISC_EDIT
  1117. } imenum_t;
  1118.  
  1119. struct itmp_
  1120.   {
  1121.       const char *lab;        /* label for button       */
  1122.       imenum_t m;        /* index                  */
  1123.       int c;            /* color when button down */
  1124.       const char *scuts;    /* keyboard short cuts   */
  1125.   };
  1126.  
  1127. static struct itmp_ imisccn[] =
  1128. {
  1129.     {"Ibrowser", IMISC_BROWSE, FL_YELLOW, "iI"},
  1130.     {"Repaint", IMISC_REPAINT, FL_GREEN, "rR"},
  1131.     {"Edit", IMISC_EDIT, FL_RED, "Ee"}
  1132. };
  1133.  
  1134. static int totalimisc = sizeof(imisccn) / sizeof(imisccn[0]);
  1135.  
  1136. /******************************************************************
  1137.  * Handle misc. requests
  1138.  ******************************************************************/
  1139. /* ARGSUSED */
  1140. static void
  1141. imisc_cb(FL_OBJECT * ob, long j)
  1142. {
  1143.  
  1144.     switch (imisccn[j].m)
  1145.       {
  1146.       case IMISC_EDIT:
  1147.       if (!cntl->visible)
  1148.           show_control_window(-1, -1, -1, -1, 0);
  1149.       else
  1150.           hide_control_window();
  1151.       break;
  1152.  
  1153.       case IMISC_BROWSE:
  1154.       ibrowse_dir((char *) 0);
  1155.       break;
  1156.  
  1157.       case IMISC_REPAINT:
  1158.       do_repaint(imgptr);
  1159.       break;
  1160.       }
  1161. }
  1162.  
  1163. /********************** progress report etc *************************/
  1164.  
  1165. #ifndef NO_TIMING
  1166. #include <time.h>
  1167. static clock_t lasttime;
  1168. #endif
  1169.  
  1170. void
  1171. remove_progress_report(void)
  1172. {
  1173.     char pp[20];
  1174.  
  1175.     if (report_level >= 0)
  1176.     remove_rotate_cursor();
  1177.  
  1178. #ifndef NO_TIMING
  1179.     lasttime = clock() - lasttime;
  1180.     lasttime /= 1000;
  1181.     sprintf(pp, "%ld msec", (long) lasttime);
  1182. #endif
  1183.  
  1184.     /*
  1185.      * following line makes sure that multiple call of this routine will not
  1186.      * screwup the timing
  1187.      */
  1188.     if (report_level > 0 && !pslider->visible)    /* already called */
  1189.     return;
  1190.  
  1191.     if (pslider->visible)
  1192.     fl_hide_object_only(pslider);
  1193.     if (ptext->visible)
  1194.     fl_hide_object_only(ptext);
  1195.  
  1196. #ifndef NO_TIMING
  1197.     show_misc_info(pp);
  1198. #endif
  1199.  
  1200. }
  1201.  
  1202. static float denorm = -1;
  1203. static int adjfactor;
  1204.  
  1205. long
  1206. progress_report(const char *s, long max_i)
  1207. {
  1208.     long every;
  1209.  
  1210.     /*
  1211.      * if not requesting progress report, set frequency to something large,
  1212.      * but can't be max_i 'cause we still want to service the emergency_Q
  1213.      * events with upate_progress_report
  1214.      */
  1215.  
  1216.     if (report_level < 0)
  1217.       {
  1218.       if (pslider->visible)
  1219.           remove_progress_report();
  1220.       return (max_i / 3);
  1221.       }
  1222.  
  1223.     rotate_cursor();
  1224.     denorm = max_i - 1;
  1225.  
  1226.     /* no reporting is desired  */
  1227.     if (report_level <= 0)
  1228.       {
  1229.       if (pslider->visible)
  1230.           remove_progress_report();
  1231.       }
  1232.     else
  1233.       {
  1234.       fl_set_object_label(ptext, s);
  1235.       fl_set_slider_value(pslider, 0.0);
  1236.       hide_misc_info();    /* this will make timing report nicer */
  1237.       if (!pslider->visible)
  1238.         {
  1239.         fl_show_object(pslider);
  1240.         fl_show_object(ptext);
  1241.         }
  1242.       }
  1243.  
  1244. #ifndef NO_TIMING
  1245.     lasttime = clock();
  1246. #endif
  1247.  
  1248.     /* if no percentage report, let cursor rotate every 10 percent */
  1249.  
  1250.     every = (denorm * 0.01 * (report_level ? percent_report : 10));
  1251.  
  1252.     /*
  1253.      * if image is large, say has a hight more than 1000, half the frequency.
  1254.      * Note that sometimes max_i is in bytes, need to take care of that
  1255.      */
  1256.  
  1257.     if (max_i > 1000 && max_i < 100000L)
  1258.       {
  1259.       every /= (adjfactor = 2);
  1260.       }
  1261.     else
  1262.     adjfactor = 1;
  1263.     return every < 1 ? 1 : every;
  1264. }
  1265.  
  1266. /*
  1267.  * we have to allow this routine to be called even if we don't what to show
  1268.  * the slider because we need to check Q-events periodically
  1269.  */
  1270. void
  1271. update_progress_report(long j)
  1272. {
  1273.     int cheat, tpercent;
  1274.  
  1275.     check_emergency();
  1276.  
  1277.     if (report_level <= 0)
  1278.       {
  1279.       if (report_level == 0)
  1280.           rotate_cursor();
  1281.       return;
  1282.       }
  1283.  
  1284.     rotate_cursor();
  1285.  
  1286.     tpercent = percent_report / adjfactor;
  1287.  
  1288.     /*
  1289.      * due to the discret nature of scan line, reported percentage can be off
  1290.      * by a few  percent. Corrected it here
  1291.      */
  1292.  
  1293.     cheat = (j * 100.0 / denorm + 0.02);
  1294.     if (cheat % percent_report)
  1295.       {
  1296.       cheat = ((cheat + 2) / tpercent) * tpercent;
  1297.       }
  1298.     if (cheat > 100)
  1299.     cheat = 100;
  1300.     fl_set_slider_value(pslider, 0.01 * cheat);
  1301. }
  1302.  
  1303. static void
  1304. create_form_cntl(void)
  1305. {
  1306.     FL_OBJECT *obj;
  1307.     int i, j, ii;
  1308.     float x, x0, y, dx, dy;
  1309.     char lp[20];
  1310.  
  1311.     cntl = fl_bgn_form(FL_NO_BOX, 345.0, 370.0);
  1312.     obj = fl_add_box(FL_UP_BOX, 0.0, 0.0, 345.0, 370.0, "");
  1313.     fl_set_object_color(obj, 12, 47);
  1314.  
  1315.     /* help buttun */
  1316.     obj = fl_add_button(FL_HIDDEN_BUTTON, 0.0, 0.0, 345.0, 370.0, "");
  1317.     fl_set_call_back(obj, help_cb, HELP_CNTL);
  1318.  
  1319.     /* editing group */
  1320.     edgrp = fl_bgn_group();
  1321.     obj = fl_add_box(FL_SHADOW_BOX, 10.0, 10.0, 220.0, 180.0, "");
  1322.     fl_set_object_color(obj, 9, 47);
  1323.  
  1324.     y = 125;
  1325.     x = x0 = 15;
  1326.     dx = 70;
  1327.     dy = 25;
  1328.     ii = Min(totaledit, MAXSHOWN - 2);
  1329.  
  1330.     for (dx = 70, dy = 25, i = j = 0; i < ii; i += 3, y -= dy, x = x0)
  1331.       {
  1332.       j = i;
  1333.       bedit[j] = fl_add_button(FL_NB, x, y, dx, dy, edit[j].name);
  1334.       fl_set_object_lsize(bedit[j], 10.0);
  1335.       fl_set_object_color(bedit[j], FL_MAGIC1, edit[j].bcolor);
  1336.       fl_set_call_back(bedit[j], edit_cb, j);
  1337.       x += dx;
  1338.       j++;
  1339.  
  1340.       if (j < totaledit)
  1341.         {
  1342.         bedit[j] = fl_add_button(FL_NB, x, y, dx, dy, edit[j].name);
  1343.         fl_set_object_lsize(bedit[j], 10.0);
  1344.         fl_set_object_color(bedit[j], FL_MAGIC1, edit[j].bcolor);
  1345.         fl_set_call_back(bedit[j], edit_cb, j);
  1346.         x += dx;
  1347.         j++;
  1348.         }
  1349.  
  1350.       if (j < totaledit)
  1351.         {
  1352.         bedit[j] = fl_add_button(FL_NB, x, y, dx, dy, edit[j].name);
  1353.         fl_set_object_lsize(bedit[j], 10.0);
  1354.         fl_set_object_color(bedit[j], FL_MAGIC1, edit[j].bcolor);
  1355.         fl_set_call_back(bedit[j], edit_cb, j);
  1356.         j++;
  1357.         }
  1358.       }
  1359.  
  1360.     maxshown = j;
  1361.     obj = fl_add_button(FL_NB, 45.0, 160.0, 155.0, 22.0, "");
  1362.     fl_set_object_boxtype(obj, FL_RSHADOW_BOX);
  1363.     fl_set_object_lcol(obj, FL_BLUE);
  1364.     fl_set_object_lsize(obj, 10.00);
  1365.     fl_set_object_color(obj, FL_MAGIC1, FL_GREEN);
  1366.     fl_set_object_lstyle(obj, FL_BOLD_STYLE);
  1367.     if (totaledit > maxshown)
  1368.       {
  1369.       fl_set_object_label(obj, "More Edit Functions");
  1370.       fl_set_call_back(obj, up_dn_cb, 0);
  1371.       }
  1372.     else
  1373.       {
  1374.       fl_set_object_label(obj, "Edit Functions");
  1375.       fl_deactivate_object(obj);
  1376.       }
  1377.     fl_end_group();
  1378.  
  1379.     /* Type conversion group */
  1380.     cgrp = fl_bgn_group();
  1381.     obj = fl_add_box(FL_SHADOW_BOX, 240.0, 10.0, 95.0, 180.0, "");
  1382.     fl_set_object_color(obj, 49, 47);
  1383.     obj = fl_add_text(FL_NORMAL_TEXT, 245.0, 170.0, 95.0, 15.0, "ImageTypes");
  1384.     fl_set_object_lcol(obj, 4);
  1385.     fl_set_object_lsize(obj, 10.000);
  1386.     fl_set_object_align(obj, FL_ALIGN_CENTER);
  1387.     fl_set_object_lstyle(obj, FL_ITALIC_STYLE);
  1388.  
  1389.     x = 245;
  1390.     y = 135;
  1391.     for (dx = 85, dy = 25, i = 0; i < totalct; i++, y -= dy)
  1392.       {
  1393.       obj = fl_add_button(FL_NORMAL_BUTTON, x, y, dx, dy, ct[i].lab);
  1394.       fl_set_object_lsize(obj, 10.00);
  1395.       fl_set_object_color(obj, FL_MAGIC1, FL_YELLOW);
  1396.       fl_set_call_back(obj, type_cb, i);
  1397.       }
  1398.  
  1399.     fl_end_group();
  1400.  
  1401.     /* External group */
  1402.     exgrp = fl_bgn_group();
  1403.     obj = fl_add_box(FL_SHADOW_BOX, 250.0, 205.0, 80.0, 120.0, "");
  1404.     fl_set_object_color(obj, 49, 47);
  1405.     obj = fl_add_text(FL_NORMAL_TEXT, 250.0, 305.0, 80.0, 15.0, "ExtBinding");
  1406.     fl_set_object_lcol(obj, 4);
  1407.     fl_set_object_lsize(obj, 10.000);
  1408.     fl_set_object_align(obj, FL_ALIGN_CENTER);
  1409.     fl_set_object_lstyle(obj, FL_BOLD_STYLE);
  1410.  
  1411.     obj = fl_add_button(FL_NB, 258.0, 235.0, 65.0, 25.0, "Filter");
  1412.     fl_set_object_lsize(obj, 10.00);
  1413.     fl_set_call_back(obj, ext_cb, EXT_FILTER);
  1414.     obj = fl_add_button(FL_NB, 258.0, 265.0, 65.0, 25.0, "Convolve");
  1415.     fl_set_object_lsize(obj, 10.00);
  1416.     fl_set_call_back(obj, ext_cb, EXT_CONVOLV);
  1417.     fl_end_group();
  1418.  
  1419.     /* Pan groups */
  1420.     pgrp = fl_bgn_group();
  1421.     obj = fl_add_box(FL_SHADOW_BOX, 10.0, 195.0, 130.0, 130.0, "");
  1422.     fl_set_object_color(obj, 49, 47);
  1423.  
  1424.     x = x0 = 30.0;
  1425.     y = 220;
  1426.     for (dx = dy = 30, i = 1; i < 10; i += 3, y += dy, x = x0)
  1427.       {
  1428.       for (j = 0; j < 3; j++, x += dx)
  1429.         {
  1430.         if ((i + j) == 5)
  1431.             strcpy(lp, "@#circle");
  1432.         else
  1433.             sprintf(lp, "@#%d", (i + j));
  1434.         obj = fl_add_button(FL_TOUCH_BUTTON, x, y, dx, dy, lp);
  1435.         fl_set_object_color(obj, 47, 3);
  1436.         fl_set_object_lcol(obj, 1);
  1437.         fl_set_call_back(obj, pan_cb, (i + j));
  1438.         }
  1439.       }
  1440.  
  1441.     pspeed = fl_add_counter(FL_NC, 15.0, 200.0, 120.0, 20.0, "");
  1442.     fl_set_object_lsize(pspeed, FL_SMALL_FONT);
  1443.     fl_set_object_lstyle(pspeed, FL_BOLD_STYLE);
  1444.     fl_set_counter_precision(pspeed, 0);
  1445.     fl_set_counter_bounds(pspeed, 0.0, 200.0);
  1446.     fl_set_counter_step(pspeed, 1, 10);
  1447.     fl_set_counter_value(pspeed, 50.0);
  1448.     fl_end_group();
  1449.  
  1450.     /* brief info about current file */
  1451.     etitle = fl_add_button(FL_NB, 15.0, 335.0, 320.0, 25.0, "None");
  1452.     fl_set_object_boxtype(etitle, FL_FRAME_BOX);
  1453.     fl_set_object_color(etitle, FL_MAGIC1, FL_GREEN);
  1454.     fl_set_object_lsize(etitle, 10.000);
  1455.     fl_set_object_align(etitle, FL_ALIGN_CENTER);
  1456.     fl_set_call_back(etitle, special_cb, 0);
  1457.  
  1458.     /* Misc control */
  1459.     mgrp = fl_bgn_group();
  1460.     obj = fl_add_box(FL_SHADOW_BOX, 150.0, 195.0, 85.0, 130.0, "");
  1461.     fl_set_object_color(obj, 49, 47);
  1462.     obj = fl_add_text(FL_NT, 155.0, 305.0, 80.0, 15.0, "Misc. Cntl");
  1463.     fl_set_object_lcol(obj, 4);
  1464.     fl_set_object_lsize(obj, 10.000);
  1465.     fl_set_object_align(obj, FL_ALIGN_CENTER);
  1466.     fl_set_object_lstyle(obj, FL_BOLD_STYLE);
  1467.  
  1468.     x = 158;
  1469.     y = 280;
  1470.     for (dx = 69, dy = 20, i = 0; i < totalmisc; i++, y -= dy)
  1471.       {
  1472.       obj = fl_add_button(FL_NB, x, y, dx, dy, misccn[i].lab);
  1473.       fl_set_object_color(obj, 47, misccn[i].bcol);
  1474.       fl_set_object_boxtype(obj, FL_BORDER_BOX);
  1475.       fl_set_object_lsize(obj, 10.00);
  1476.       fl_set_call_back(obj, misc_cb, misccn[i].cbi);
  1477.       fl_set_button_shortcut(obj, misccn[i].scut);
  1478.       }
  1479.  
  1480.     fl_end_group();
  1481.     fl_end_form();
  1482. }
  1483.  
  1484.  
  1485. static void
  1486. create_form_info(void)
  1487. {
  1488.     FL_OBJECT *obj;
  1489.     int i, j;
  1490.     float x, y, dx, dy, x0;
  1491.  
  1492.     info = fl_bgn_form(FL_NO_BOX, 260.0, 268.0);
  1493.     obj = fl_add_box(FL_UP_BOX, 0.0, 0.0, 260.0, 268.0, "");
  1494.     fl_set_object_color(obj, 12, 47);
  1495.     obj = fl_add_button(FL_HB, 0.0, 0.0, 260, 268.0, "");
  1496.     fl_set_call_back(obj, version_cb, 0);
  1497.  
  1498.     /* Reportint group */
  1499.     infog = fl_bgn_group();
  1500.     obj = fl_add_box(FL_FRAME_BOX, 100.0, 85.0, 150.0, 130.0, "");
  1501.     fl_set_object_color(obj, 9, 47);
  1502.     obj = fl_add_text(FL_NT, 110.0, 195.0, 140.0, 15.0, "CurrentFile");
  1503.     fl_set_object_lcol(obj, 4);
  1504.     fl_set_object_lsize(obj, 10.000);
  1505.     fl_set_object_align(obj, FL_ALIGN_CENTER);
  1506.     fl_set_object_lstyle(obj, FL_BOLD_STYLE);
  1507.  
  1508.     x = 105.0;
  1509.     y = 170.0;
  1510.     for (dx = 140, dy = 20, i = 0; i < 5; y -= dy, i++)
  1511.       {
  1512.       freport[i] = fl_add_text(FL_NORMAL_TEXT, x, y, dx, dy, "");
  1513.       fl_set_object_boxtype(freport[i], FL_FRAME_BOX);
  1514.       fl_set_object_lsize(freport[i], 10.0);
  1515.       fl_set_object_align(freport[i], FL_ALIGN_CENTER);
  1516.       }
  1517.     fl_set_object_label(freport[0], "None");
  1518.     /* add a hidden button to shown more info */
  1519.     obj = fl_add_button(FL_HIDDEN_BUTTON, 100, 85, 150, 130, "");
  1520.     fl_set_call_back(obj, show_image_info, 0);
  1521.     fl_end_group();
  1522.  
  1523.  
  1524.     /* progress report group */
  1525.     fl_bgn_group();
  1526.     pslider = fl_add_valslider(FL_HFS, 10.0, 40.0, 240.0, 25.0, "");
  1527.     fl_set_object_color(pslider, 12, 3);
  1528.     fl_set_object_lsize(pslider, 10.000);
  1529.     fl_set_object_lstyle(pslider, FL_BOLD_STYLE);
  1530.     fl_set_slider_precision(pslider, 2);
  1531.     fl_set_slider_value(pslider, 0.0);
  1532.     fl_set_slider_bounds(pslider, 0.0, 1.0);
  1533.     pslider->active = 0;
  1534.  
  1535.     ptext = fl_add_text(FL_NORMAL_TEXT, 10.0, 65.0, 240.0, 20.0, "");
  1536.     fl_set_object_boxtype(ptext, FL_FLAT_BOX);
  1537.     fl_set_object_color(ptext, 12, 12);
  1538.     fl_set_object_lsize(ptext, 10.000);
  1539.     fl_set_object_align(ptext, FL_ALIGN_CENTER);
  1540.     fl_set_object_lstyle(ptext, FL_BOLD_STYLE);
  1541.     fl_end_group();
  1542.  
  1543.  
  1544.     /* misc reporting group */
  1545.     mrptg = fl_bgn_group();
  1546.     x = x0 = 10.0;
  1547.     for (y = 60, dx = 120, dy = 20, i = 0; i < 4; i += 2, y -= dy + 1, x = x0)
  1548.       {
  1549.       for (j = 0; j < 2; j++, x += dx + 1)
  1550.         {
  1551.         mreport[i + j] = fl_add_text(FL_NT, x, y, dx, dy, "");
  1552.         fl_set_object_boxtype(mreport[i + j], FL_BORDER_BOX);
  1553.         fl_set_object_lsize(mreport[i + j], 10.000);
  1554.         }
  1555.       }
  1556.     fl_end_group();
  1557.  
  1558.     /* File I/O  */
  1559.  
  1560.     obj = fl_add_box(FL_SHADOW_BOX, 10.0, 90.0, 80.0, 125.0, "");
  1561.     fl_set_object_color(obj, 49, 47);
  1562.     obj = fl_add_text(FL_NT, 15.0, 195.0, 70.0, 15.0, "File I/O");
  1563.     fl_set_object_lcol(obj, 4);
  1564.     fl_set_object_lsize(obj, 10.000);
  1565.     fl_set_object_align(obj, FL_ALIGN_CENTER);
  1566.     fl_set_object_lstyle(obj, FL_BOLD_STYLE);
  1567.  
  1568.     iogroup = fl_bgn_group();
  1569.     x = 15;
  1570.     y = 170.0;
  1571.     for (dx = 70, dy = 20, i = 0; i < totalfio - 1; y -= (dy + 4), i++)
  1572.       {
  1573.       obj = fl_add_button(FL_NORMAL_BUTTON, x, y, dx, dy, fiob[i].lab);
  1574.       fl_set_object_boxtype(obj, FL_RSHADOW_BOX);
  1575.       fl_set_object_color(obj, 47, 12);
  1576.       fl_set_object_lsize(obj, 10.000);
  1577.       fl_set_call_back(obj, file_cb, fiob[i].cbi);
  1578.       fl_set_button_shortcut(obj, fiob[i].scut);
  1579.       }
  1580.     fl_end_group();
  1581.  
  1582.     /* the quit button */
  1583.     obj = fl_add_button(FL_NORMAL_BUTTON, x, y, dx, dy, fiob[i].lab);
  1584.     fl_set_object_boxtype(obj, FL_RSHADOW_BOX);
  1585.     fl_set_object_color(obj, 47, 12);
  1586.     fl_set_object_lsize(obj, 10.000);
  1587.     fl_set_call_back(obj, file_cb, fiob[i].cbi);
  1588.     fl_set_button_shortcut(obj, fiob[i].scut);
  1589.  
  1590.  
  1591.     /* misc control groups */
  1592.     fl_bgn_group();
  1593.  
  1594.     x = 10.0;
  1595.     for (y = 10, dx = 80, dy = 25, i = 0; i < totalimisc; i++, x += dx)
  1596.       {
  1597.       obj = fl_add_button(FL_NB, x, y, dx, dy, imisccn[i].lab);
  1598.       fl_set_object_lsize(obj, 10.00);
  1599.       fl_set_object_color(obj, FL_MAGIC1, imisccn[i].c);
  1600.       fl_set_call_back(obj, imisc_cb, i);
  1601.       }
  1602.     fl_end_group();
  1603.  
  1604.     obj = fl_add_button(FL_NB, 43.0, 222.0, 184.0, 30.0, rm_rcs_kw(sver));
  1605.     fl_set_object_boxtype(obj, FL_FRAME_BOX);
  1606.     fl_set_object_color(obj, 12, FL_GREEN);
  1607.     fl_set_object_lcol(obj, FL_BLUE);
  1608.     fl_set_object_lstyle(obj, FL_BOLD_STYLE);
  1609.     fl_set_object_lsize(obj, 11.0);
  1610.     fl_set_call_back(obj, version_cb, 0);
  1611.  
  1612.     fl_end_form();
  1613.     fl_scale_form(info, 1.04, 1.04);
  1614. }
  1615.  
  1616. static void
  1617. create_forms(void)
  1618. {
  1619.     static int ok;
  1620.     if (!ok)
  1621.       {
  1622.       create_form_cntl();
  1623.       create_form_info();
  1624.       ok = 1;
  1625.       }
  1626. }
  1627.